package com.newtouch.xcd.cms.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.newtouch.xcd.cms.entity.Customer;
import com.newtouch.xcd.cms.mapper.CustomerMapper;
import com.newtouch.xcd.cms.service.CustomerService;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 本表存放客户的相关信息 服务实现类
 * </p>
 *
 * @author dongyuefeng
 * @since 2020-05-21
 */
@Component
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {


    /**
     * 根据手机号查找用户信息
     * @param phone
     * @return
     */
    @Override
    public List<Customer> queryByPhone(String phone){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("crm_hxhuww",phone);
        return this.list(queryWrapper);
    }

    /**
     * 根据客户分类查找用户信息
     * @param origin
     * @return
     */
    @Override
    public List<String> queryByOrigin(String origin){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("origin",origin);
        return this.list(queryWrapper);
    }

    /**
     * 根据客户分类查找用户信息
     * @param origin1
     * @param origin2
     * @return
     */
    @Override
    public List<Customer> queryByOrigin(String origin1,String origin2){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("origin",origin1);

        List<Customer> allCustomerList = this.list(queryWrapper);
        allCustomerList = allCustomerList.stream().filter(o->o.getOrigin().contains(origin2))
                .collect(Collectors.toList());

        return allCustomerList;
    }
}
